<template>
	<div>
		<!--头部返回按钮-->
		<router-link tag="div" to="/" class="header-abs" v-show="showAbs">
			<i class="iconfont back-icon">&#xe624;</i>
		</router-link>
		<!--头部区块-->
		<div class="header-fixed" v-show="!showAbs" :style="opacityStyle">
			<router-link to="/">
				<div class="header-left">
     				<i class="iconfont back-icon">&#xe624;</i>
   				</div>
			</router-link>
		景点详情
		</div>
	</div>
</template>

<script>
export default {
	name: "DetailHeader",
	data () {
		return {
			showAbs: true,
			opacityStyle: {
				opacity: 0
			}
		}
	},
	methods: {
		handleScroll () {
			const top = document.documentElement.scrollTop
			if (top > 36) {
				let opacity = top / 140
				//判断 opacity 的值是否大于 1，如果大于 1，则让它等于 1
				opacity = opacity > 1 ? 1 : opacity
				this.opacityStyle = {
					opacity: opacity
				}
				this.showAbs = false
			} else {
				this.showAbs = true
			}
		}
	},
	activated () {
		window.addEventListener("scroll",this.handleScroll)
	},
	deactivated () {
		window.removeEventListener("scroll",this.handleScroll)
	}
}
</script>

<style lang="stylus" scoped>
	@import "../../../assets/styles/varibles.styl"
	.header-abs
		position: absolute
		left: .1rem
		top: .1rem
		width: .4rem
		height: .4rem
		border-radius: .2rem
		background: rgba(0,0,0,.8)
		.back-icon
			position: absolute
			left: 0.1rem
			top: 0.12rem
			color: #fff
			font-weight: bold
	.header-fixed
		position: fixed
		top: 0
		left: 0
		right: 0
		z-index: 99
		height: .36rem
		line-height: .36rem
		color: #f5f5f5
		text-align: center
		background: $bgColor
		font-size: .16rem
		.header-left
			position: absolute
			width: 0.4rem
			color: #fff
</style>
